/*
 * 	<pre>
 *	EasyPeas.
 *  Copyright (C) 2007 S Owen
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Jul 24, 2007
 * TeskInvokerImplActions.java
 * </pre>
 */
package org.easypeas.invocation;

import static org.junit.Assert.assertEquals;

import java.util.Map;

import org.easypeas.EasyPeasConstants;
import org.easypeas.exceptions.ResourceInvocationFailure;
import org.easypeas.exceptions.UnresolvedMethodException;
import org.easypeas.mappings.Mappings;
import org.easypeas.mappings.annotated.AnnotatedMappings;
import org.junit.BeforeClass;
import org.junit.Test;

public class TeskInvokerImplActions {

	Invoker invoker = new InvokerImpl();

	private static Mappings mappings;

	@BeforeClass
	public static void initMappings() throws Exception {
		try {
			if (mappings == null)
				mappings = new AnnotatedMappings(TestInvokerImpl.class
						.getResource("/testeasypeas.classes"));
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	@Test
	public void simple() throws Exception {
		Map<String, Object> result = invoker.invokeActionPath(null, null,
				mappings, "/bob/kiss");
		assertEquals("/bob/success.vm", result.get(EasyPeasConstants.EASYPEA_FORWARD));
	}

	@Test
	public void objectAdded() throws Exception {
		Map<String, Object> result = invoker.invokeActionPath(null, null,
				mappings, "/bob/anAction");
		assertEquals("/bob/failure.vm", result.get(EasyPeasConstants.EASYPEA_FORWARD));
		assertEquals("a b c", result.get("pea"));
	}

	@Test(expected = UnresolvedMethodException.class)
	public void unresolvedPath() throws Exception {
		invoker.invokeActionPath(null, null, mappings, "/bob/nonsense");
	}

	@Test(expected = ResourceInvocationFailure.class)
	public void failure() throws Exception {
		invoker.invokePath(null, null, mappings, "/bob/failure");
	}

}
